﻿using System;
using System.Web.Mvc;
using CaptchaMVC.Attribute;
using SocialNetwork.Models;

namespace SocialNetwork.Controllers
{
    public class FeedbackController : Controller
    {
        private FBEntities _feedbacks;

        public FBEntities feedbacks { get; set; }

        public ActionResult FeedbackForm()
        {
            return View();
        }

        [HttpPost]
        [CaptchaVerify("Incorrect symbols")]
        public ActionResult FeedbackForm(FeedbackModel fbModel)
        {
            if (ModelState.IsValid)
            {
                var feed = new FBEntities();
                feed.FeedbackData.AddObject(
                    new FeedbackData()
                        {
                            Id = Guid.NewGuid(),
                            Username = User.Identity.Name,
                            Date = DateTime.Now,
                            Subject = fbModel.Subject,
                            Message = fbModel.Message
                        }
                    );
                feed.SaveChanges();
                return RedirectToAction("Index", "Home");
            }

            return View(fbModel);
        }

        [Authorize(Roles = "Administrator, koyot")]
        public ActionResult FeedbackList()
        {
            var fb = feedbacks.FeedbackData;
            return View();
        }
    }
}
